package com.logistics.menu.controller;

import com.logistics.menu.entity.model.MenuPager;
import com.logistics.menu.entity.model.MenuSave;
import com.logistics.menu.service.MenuService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("sys/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 查找展示的菜单
     * @return
     * @throws MessageException
     */
    @GetMapping("/menuList/{device}")
    @LoggerListener(businessName = "根据角色查询菜单列表", methodName = LoggerMethod.SEARCH)
    public ResponseEntity menuList(@PathVariable("device") String device) throws MessageException {
        return ResponseUtil.success(menuService.menus(device));
    }

    /**
     * 获取所有菜单树形
     * @return
     */
    @GetMapping("menuAll")
    @LoggerListener(businessName = "查询所有菜单树形", methodName = LoggerMethod.SEARCH)
    public ResponseEntity menuAll(){
        return ResponseUtil.success(menuService.menuAll());
    }

    /**
     * 查找分页菜单
     * @param param
     * @return
     */
    @PostMapping("pager")
    @LoggerListener(businessName = "分页查询菜单列表", methodName = LoggerMethod.SEARCH)
    public ResponseEntity pager(@RequestBody MenuPager param){
        return ResponseUtil.success(menuService.pager(param));
    }

    /**
     * 查找详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("details/{id}")
    @LoggerListener(businessName = "查询菜单详细", methodName = LoggerMethod.SEARCH)
    public ResponseEntity details(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(menuService.details(id));
    }

    /**
     * 删除
     * @param ids
     * @return
     * @throws MessageException
     */
    @DeleteMapping("remove/{ids}")
    @LoggerListener(businessName = "删除菜单", methodName = LoggerMethod.DELETE)
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        menuService.delete(ids);
        return ResponseUtil.success();
    }

    /**
     * 保存
     * @param save
     * @return
     */
    @PutMapping("save")
    @LoggerListener(businessName = "保存菜单信息", methodName = LoggerMethod.SAVE)
    public ResponseEntity save(@RequestBody MenuSave save){
        menuService.save(save);
        return ResponseUtil.success();
    }
}
